home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / libtiff / tif_aux.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  6KB  |  205 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_aux.c,v 1.18 93/06/28 16:15:41 sam Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1991, 1992 Sam Leffler
  7.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  8.  *
  9.  * Permission to use, copy, modify, distribute, and sell this software and 
  10.  * its documentation for any purpose is hereby granted without fee, provided
  11.  * that (i) the above copyright notices and this permission notice appear in
  12.  * all copies of the software and related documentation, and (ii) the names of
  13.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  14.  * publicity relating to the software without the specific, prior written
  15.  * permission of Sam Leffler and Silicon Graphics.
  16.  * 
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  18.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  19.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  20.  * 
  21.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  22.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  23.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  24.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  25.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  26.  * OF THIS SOFTWARE.
  27.  */
  28.  
  29. /*
  30.  * TIFF Library.
  31.  *
  32.  * Auxiliary Support Routines.
  33.  */
  34. #include "tiffiop.h"
  35.  
  36. #ifdef COLORIMETRY_SUPPORT
  37. #include <math.h>
  38.  
  39. static void
  40. DECLARE1(TIFFDefaultTransferFunction, TIFFDirectory*, td)
  41. {
  42.     u_short **tf = td->td_transferfunction;
  43.     int i, n = 1<<td->td_bitspersample;
  44.  
  45.     tf[0] = (u_short *)_TIFFmalloc(n * sizeof (u_short));
  46.     tf[0][0] = 0;
  47.     for (i = 1; i < n; i++)
  48.         tf[0][i] = (u_short)floor(65535.*pow(i/(n-1.), 2.2) + .5);
  49.     if (td->td_samplesperpixel - td->td_matteing > 1) {
  50.         tf[1] = (u_short *)_TIFFmalloc(n * sizeof (u_short));
  51.         memcpy(tf[1], tf[0], n * sizeof (u_short));
  52.         tf[2] = (u_short *)_TIFFmalloc(n * sizeof (u_short));
  53.         memcpy(tf[2], tf[0], n * sizeof (u_short));
  54.     }
  55. }
  56.  
  57. static void
  58. DECLARE1(TIFFDefaultRefBlackWhite, TIFFDirectory*, td)
  59. {
  60.     int i;
  61.  
  62.     td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float));
  63.     for (i = 0; i < 3; i++) {
  64.         td->td_refblackwhite[2*i+0] = 0;
  65.         td->td_refblackwhite[2*i+1] = 1L<<td->td_bitspersample;
  66.     }
  67. }
  68. #endif
  69.  
  70. /*
  71.  * Like TIFFGetField, but return any default
  72.  * value if the tag is not present in the directory.
  73.  *
  74.  * NB:    We use the value in the directory, rather than
  75.  *    explcit values so that defaults exist only one
  76.  *    place in the library -- in TIFFDefaultDirectory.
  77.  */
  78. DECLARE3(TIFFVGetFieldDefaulted, TIFF*, tif, u_int, tag, va_list, ap)
  79. {
  80.     TIFFDirectory *td = &tif->tif_dir;
  81.     int i;
  82.  
  83.     if (TIFFVGetField(tif, tag, ap))
  84.         return (1);
  85.     switch (tag) {
  86.     case TIFFTAG_SUBFILETYPE:
  87.         *va_arg(ap, u_short *) = td->td_subfiletype;
  88.         return (1);
  89.     case TIFFTAG_BITSPERSAMPLE:
  90.         *va_arg(ap, u_short *) = td->td_bitspersample;
  91.         return (1);
  92.     case TIFFTAG_THRESHHOLDING:
  93.         *va_arg(ap, u_short *) = td->td_threshholding;
  94.         return (1);
  95.     case TIFFTAG_FILLORDER:
  96.         *va_arg(ap, u_short *) = td->td_fillorder;
  97.         return (1);
  98.     case TIFFTAG_ORIENTATION:
  99.         *va_arg(ap, u_short *) = td->td_orientation;
  100.         return (1);
  101.     case TIFFTAG_SAMPLESPERPIXEL:
  102.         *va_arg(ap, u_short *) = td->td_samplesperpixel;
  103.         return (1);
  104.     case TIFFTAG_ROWSPERSTRIP:
  105.         *va_arg(ap, u_long *) = td->td_rowsperstrip;
  106.         return (1);
  107.     case TIFFTAG_MINSAMPLEVALUE:
  108.         *va_arg(ap, u_short *) = td->td_minsamplevalue;
  109.         return (1);
  110.     case TIFFTAG_MAXSAMPLEVALUE:
  111.         *va_arg(ap, u_short *) = td->td_maxsamplevalue;
  112.         return (1);
  113.     case TIFFTAG_PLANARCONFIG:
  114.         *va_arg(ap, u_short *) = td->td_planarconfig;
  115.         return (1);
  116.     case TIFFTAG_GROUP4OPTIONS:
  117.         *va_arg(ap, u_long *) = td->td_group4options;
  118.         return (1);
  119.     case TIFFTAG_RESOLUTIONUNIT:
  120.         *va_arg(ap, u_short *) = td->td_resolutionunit;
  121.         return (1);
  122.     case TIFFTAG_PREDICTOR:
  123.         *va_arg(ap, u_short *) = td->td_predictor;
  124.         return (1);
  125. #ifdef CMYK_SUPPORT
  126.     case TIFFTAG_DOTRANGE:
  127.         *va_arg(ap, u_short *) = 0;
  128.         *va_arg(ap, u_short *) = (1<<td->td_bitspersample)-1;
  129.         return (1);
  130.     case TIFFTAG_INKSET:
  131.         *va_arg(ap, u_short *) = td->td_inkset;
  132.         return (1);
  133. #endif
  134.     case TIFFTAG_EXTRASAMPLES:
  135.         *va_arg(ap, u_short *) = td->td_matteing;
  136.         *va_arg(ap, u_short **) = &td->td_matteing;
  137.         return (1);
  138.     case TIFFTAG_MATTEING:
  139.         *va_arg(ap, u_short *) = td->td_matteing;
  140.         return (1);
  141.     case TIFFTAG_TILEDEPTH:
  142.         *va_arg(ap, u_long *) = td->td_tiledepth;
  143.         return (1);
  144.     case TIFFTAG_DATATYPE:
  145.         *va_arg(ap, u_short *) = td->td_sampleformat-1;
  146.         return (1);
  147.     case TIFFTAG_IMAGEDEPTH:
  148.         *va_arg(ap, u_short *) = td->td_imagedepth;
  149.         return (1);
  150. #ifdef YCBCR_SUPPORT
  151.     case TIFFTAG_YCBCRCOEFFICIENTS:
  152.         if (!td->td_ycbcrcoeffs) {
  153.             td->td_ycbcrcoeffs = (float *)
  154.                 _TIFFmalloc(3*sizeof (float));
  155.             /* defaults are from CCIR Recommendation 601-1 */
  156.             td->td_ycbcrcoeffs[0] = .299;
  157.             td->td_ycbcrcoeffs[1] = .587;
  158.             td->td_ycbcrcoeffs[2] = .114;
  159.         }
  160.         *va_arg(ap, float **) = td->td_ycbcrcoeffs;
  161.         return (1);
  162.     case TIFFTAG_YCBCRSUBSAMPLING:
  163.         *va_arg(ap, u_short *) = td->td_ycbcrsubsampling[0];
  164.         *va_arg(ap, u_short *) = td->td_ycbcrsubsampling[1];
  165.         return (1);
  166.     case TIFFTAG_YCBCRPOSITIONING:
  167.         *va_arg(ap, u_short *) = td->td_ycbcrpositioning;
  168.         return (1);
  169. #endif
  170. #ifdef COLORIMETRY_SUPPORT
  171.     case TIFFTAG_TRANSFERFUNCTION:
  172.         if (!td->td_transferfunction[0])
  173.             TIFFDefaultTransferFunction(td);
  174.         *va_arg(ap, u_short **) = td->td_transferfunction[0];
  175.         if (td->td_samplesperpixel - td->td_matteing > 1) {
  176.             *va_arg(ap, u_short **) = td->td_transferfunction[1];
  177.             *va_arg(ap, u_short **) = td->td_transferfunction[2];
  178.         }
  179.         return (1);
  180.     case TIFFTAG_REFERENCEBLACKWHITE:
  181.         if (!td->td_refblackwhite)
  182.             TIFFDefaultRefBlackWhite(td);
  183.         *va_arg(ap, float **) = td->td_refblackwhite;
  184.         return (1);
  185. #endif
  186.     }
  187.     return (0);
  188. }
  189.  
  190. /*
  191.  * Like TIFFGetField, but return any default
  192.  * value if the tag is not present in the directory.
  193.  */
  194. /*VARARGS2*/
  195. DECLARE2V(TIFFGetFieldDefaulted, TIFF*, tif, u_int, tag)
  196. {
  197.     int ok;
  198.     va_list ap;
  199.  
  200.     VA_START(ap, tag);
  201.     ok =  TIFFVGetFieldDefaulted(tif, tag, ap);
  202.     va_end(ap);
  203.     return (ok);
  204. }
  205.